<?php
namespace Action;

class Action {
	/**
	 * deps:Action::ls,Action::save
	 */
	public function index() {
		global $o;
		$o->Model->Action->scan ();
		require_once ROOT . '/template/action_index.html';
	}
	
	public function ls() {
		global $o;
		$aList = $o->Db->ls ( array (
				'table' => 'actions',
				'page' => $_GET ['pageIndex'],
				'limit' => $_GET ['pageSize'] ? $_GET ['pageSize'] : $o->Config->get ( 'base.limit' ),
				'sort' => array (
						$_GET ['sortField'] => $_GET ['sortOrder'] 
				) 
		) );
		exit ( json_encode ( $aList ) );
	}
	
	public function save() {
		global $o;
		$aInfo = json_decode ( $_POST ['info'], true );
		exit ( $o->Model->Action->update ( $aInfo [0] ) );
	}
	
	public function tree() {
		global $o;
		$aTree = $o->Model->Action->getTree ();
		exit ( json_encode ( $aTree ) );
	}
}
?>